<template>
  <el-dialog
      :title="title"
      custom-class="x-large-dialog"
      :visible="visible"
      append-to-body
      @open="open"
      @close="close"
  >
    <div class="search-pannel">
      <el-form
          class="search-form"
          :model="postData"
          :rules="postRules"
          ref="postForm"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="房屋标题" prop="name">
              <el-input v-model="postData.name" placeholder="请输入房屋标题" maxlength="20" show-word-limit></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所在地区" prop="areaId">
              <el-cascader
                  v-model="postData.areaId"
                  :options="disableAreaList"
                  :props="areaDefaultProps"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="租金" prop="rent">
              <el-input v-model.number="postData.rent" placeholder="请输入租金"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="房屋描述" prop="description">
              <el-input type="textarea" v-model="postData.description" placeholder="请输入房屋描述" maxlength="500" show-word-limit></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="地址" prop="address">
              <el-input type="address" :rows="6" v-model="postData.address" placeholder="请选择位置" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="地图定位" prop="address">
              <map-location @showAddress="showAddress" :marker="{ lon: postData.lon, lat: postData.lat }" @showLocation="showLocation" isShouldMarker />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { _post, _put, _getDetail } from '../src/store'
import { getAllArea, postDialog } from '@/mixins'

export default {
  name: 'postDialog',
  mixins: [postDialog, getAllArea],
  data() {
    return {
      postData: {
        name: '',
        address: '',
        rent: '',
        lon: '',
        lat: '',
        areaId: '',
        description: ''
      },
      postRules: {
        name: [{ required: true, message: '请输入房屋标题', trigger: 'blur' }],
        address: [{ required: true, message: '请选择位置', trigger: 'blur' }],
        rent: [{ required: true, message: '请输入租金', trigger: 'blur' }],
        areaId: [{ required: true, message: '请选择地区', trigger: 'submit' }],
        description: [{ required: true, message: '请输入描述', trigger: 'blur' }]
      },
      addFunc: _post,
      editFunc: _put,
      detailFunc: _getDetail
    }
  },
  methods: {
    showAddress(address) {
      this.postData.address = address
    },
    showLocation(e) {
      this.postData.lon = e.lon
      this.postData.lat = e.lat
    }
  }
}
</script>

<style scoped>

</style>
